

import os

import mmcv
# using a pre-trained detector. 预训练配置
from mmcv import Config

from mmdet.datasets import build_dataset
from mmdet.models import build_detector
from mmdet.apis import train_detector, inference_detector, show_result_pyplot

from mmdet.apis import init_detector, inference_detector, show_result_pyplot

# root_path=r"/project/train/src_repo/mmdetection/"
root_path=r"/home/deepin/Documents/ji_pingtai/mmdetection/"

config_file = root_path+'work_dir/cocoDataset_cfgformat.py'

checkpoint_file = root_path+'work_dir/best_bbox_mAP_epoch_20.pth'

device = 'cuda:0'

# 初始化检测器--构建模型
model = init_detector(config_file, checkpoint_file, device=device)

# 查看 faster RCNN模型结构：
for name,module in model.named_children():
    print(name)
    [ print(F'    {n}') for n,_ in module.named_children() ]



# 推理 显示
# img = mmcv.imread(root_path+'data/coco/val2017/ZDSmask20220829_V8_train_office_2_003505.jpg')
img = mmcv.imread(root_path+'data/coco/val2017/2.jpg')

result = inference_detector(model, img) # -------如何 把 训练完成的，进行推理，这个不知道  如何加载呢
# show_result_pyplot(model, img, result,score_thr=0.4,out_file='1.jpg') #显示
show_result_pyplot(model, img, result,score_thr=0.4) #显示

